package com.itheima.web;

import com.itheima.pojo.AddressBook;
import com.itheima.result.R;
import com.itheima.service.AddressBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author: 斌
 * @DateTime: 2023年02月12日  16:06:33
 * @Description: com.itheima.web
 * @Version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/addressBook")
public class AddressBookController {
    @Autowired
    private AddressBookService addressBookService;

    @PostMapping()
    public R addAddress(@RequestBody AddressBook addressBook, HttpSession session) {
        return addressBookService.addAddress(addressBook,session);
    }
    @PutMapping("/default")
    public R updateDefaultAddress(@RequestBody  AddressBook addressBook) {
        return addressBookService.updateDefaultAddress(addressBook);
    }
    @GetMapping("/default")
    public R queryDefaultAddress() {
        return addressBookService.queryDefaultAddress();
    }
    @GetMapping("/list")
    public R queryAddressList() {
        return addressBookService.queryAddressList();
    }
    @DeleteMapping
    public R removeAddressList(@RequestParam("ids") List<Long> ids, HttpSession session) {
        return addressBookService.removeAddressList(ids,session);
    }
    @PutMapping
    public R updateAddress(@RequestBody AddressBook addressBook) {
        return addressBookService.updateAddress(addressBook);
    }

    @GetMapping("/{id}")
    public R queryAddressById(@PathVariable Long id) {
        return addressBookService.queryAddressById(id);
    }
}
